package controller;

import entity.UserInfo;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.UserInfoService;

@WebServlet("/UserLoginServlet")
public class UserLogin extends HttpServlet {

    UserInfoService userInfoService = new UserInfoService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String passWord = req.getParameter("passWord");
        if (userInfoService.checkPassWord(userName, passWord)) {
            //登陆成功
            UserInfo userInfo = userInfoService.selectUserInfoByUserName(userName);
            //记住用户
            req.getSession().setAttribute("userInfo", userInfo);
            req.getRequestDispatcher("user-login-success.jsp").forward(req, resp);
        } else {
            //登陆失败
            req.getRequestDispatcher("user-login-fail.jsp").forward(req, resp);
        }
    }

}
